Skip to content

fix: correct cadModel positionOffset Z-axis for JLCPCB imports - #365

Open
mendarb wants to merge 1 commit into
tscircuit:mainfrom
mendarb:fix/cad-model-position-offset-axis
Open

fix: correct cadModel positionOffset Z-axis for JLCPCB imports#365
mendarb wants to merge 1 commit into
tscircuit:mainfrom
mendarb:fix/cad-model-position-offset-axis

Conversation

@mendarb

@mendarb mendarb commented Mar 20, 2026

Copy link
Copy Markdown

Summary

Fixes #123

/claim #123

  • Z-offset unit parsing: Bare numeric z values from EasyEDA SVG nodes were incorrectly treated as mils (mm("Xmil")), but they are actually in pixel units (1px = 10mil = 0.254mm). Now uses mil10ToMm() consistent with how x and y offsets are already parsed.

  • Z positioning logic: The centerZ calculation incorrectly added/subtracted half the model thickness (thicknessAlongWorldZ / 2), causing 3D models to float above or sink below the board surface. Simplified to position the model origin directly at the board surface (±t) plus the EasyEDA z-offset, matching how EasyEDA models are actually authored.

What was wrong

The parseCadOffsetsFromSvgNode function used mm("Xmil") for bare z values, while x and y used mil10ToMm(). EasyEDA uses pixel units (1px = 10mil) for all three axes, so the z conversion was off by a factor of 10.

Additionally, the final Z positioning added half the model thickness to try to place the bottom of the model on the board surface, but this assumption was incorrect for many component orientations and caused visible misalignment.

Test plan

  • All 85 existing tests pass (0 failures)
  • No snapshot changes needed — the fix only affects the fallback path when OBJ metadata bounds are unavailable
  • Verified the fix produces correct board-surface-aligned positions

🤖 Generated with Claude Code

…ports

Two bugs in the Z-axis positioning of 3D models imported from EasyEDA/JLCPCB:

1. Z-offset unit parsing: bare numeric z values from EasyEDA SVG nodes were
   treated as mils, but they are actually in pixel units (1px = 10mil = 0.254mm),
   consistent with how x/y offsets are parsed via mil10ToMm().

2. Z positioning logic: the centerZ calculation incorrectly added/subtracted
   half the model thickness (thicknessAlongWorldZ/2), causing models to float
   above or sink below the board surface. Simplified to position the model
   origin directly at the board surface (±t) plus the EasyEDA z-offset.

Fixes tscircuit#123

/claim tscircuit#123

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cadModel positionOffset axis are not calculated correctly when importing from jlcpcb

1 participant